package com.iter.devbox.juc;

import java.util.concurrent.CountDownLatch;

public class MyCountDownLatch {
	
	public static class MyRunable implements Runnable {
		
		@Override
	    public void run() {
			try {
				CountDownLatch latch = new CountDownLatch(1);//实例化一计数值为1的计数器;
				System.out.println("A：什么时候吃饭啊！");
				System.out.println("当前计数器值：" + latch.getCount());
				latch.countDown();
				System.out.println("当前计数器值：" + latch.getCount());
				latch.await();//会等待计速器变0才执行下面的代码
				System.out.println("B：饭正在做，一会就好！");
			} catch (Throwable e) {
				e.printStackTrace();
			}
	    }
	}
 
    public static void main(String[] args) throws InterruptedException {
    	MyCountDownLatch.MyRunable myRunable = new MyCountDownLatch.MyRunable();
    	Thread thread = new Thread(myRunable);
		thread.start();
    }
}
